package com.cyy.content.api;

import com.cyy.content.model.dto.BindTeachplanMediaDto;
import com.cyy.content.model.dto.SaveTeachplanDto;
import com.cyy.content.model.dto.TeachPlanDto;
import com.cyy.content.service.TeachplanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author cyy
 * @date 2025/1/20
 * @description TeachPlanController
 */
@Api(value = "课程计划编辑接口",tags = "课程计划编辑接口")
@RestController
public class TeachPlanController {

    @Autowired
    private TeachplanService teachplanService;

    @ApiOperation("查询课程计划树形结构")
    @ApiImplicitParam(value = "courseId",name = "课程Id",required = true,dataType = "Long",paramType = "path")
    @GetMapping("/teachplan/{courseId}/tree-nodes")
    public List<TeachPlanDto> getTreeNodes(@PathVariable Long courseId){
        return teachplanService.findTeachPlanTree(courseId);
    }

    @ApiOperation("课程计划创建或修改")
    @PostMapping("/teachplan")
    public void saveTeachPlan(@RequestBody SaveTeachplanDto teachPlanDto){
        teachplanService.saveTeachPlan(teachPlanDto);
    }

    /**
     * 删除第一级别的大章节时要求大章节下边没有小章节时方可删除。
     * 删除第二级别的小章节的同时需要将teachplan_media表关联的信息也删除。
     * @param teachplanId
     */
    @ApiOperation("删除课程计划")
    @DeleteMapping("/teachplan/{teachplanId}")
    public void deleteTeachPlan(@PathVariable Long teachplanId){
        teachplanService.deleteTeachPlan(teachplanId);
    }

    /**
     * 参数1：movedown  为 移动类型，表示向下移动
     * 参数2：43为课程计划id
     * @param teachplanId
     */
    @ApiOperation("上移课程计划")
    @PostMapping("/teachplan/moveup/{teachplanId}")
    public void moveUpTeachPlan(@PathVariable Long teachplanId){
        teachplanService.moveUpTeachPlan(teachplanId);
    }

    @ApiOperation("下移课程计划")
    @PostMapping("/teachplan/movedown/{teachplanId}")
    public void moveDownTeachPlan(@PathVariable Long teachplanId){
        teachplanService.moveDownTeachPlan(teachplanId);
    }

    @ApiOperation(value = "课程计划和媒资信息绑定")
    @PostMapping("/teachplan/association/media")
    public void associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto){
        teachplanService.associationMedia(bindTeachplanMediaDto);
    }


}
